package com.rskj.res59mng.core.controller;


import com.rskj.res59mng.core.entity.LoginForm;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.UnknownAccountException;
//import org.apache.shiro.authc.UsernamePasswordToken;
//import org.apache.shiro.session.Session;
//import org.apache.shiro.subject.Subject;


/**
 * 程序入口
 *
 */
@Controller
public class HomeController {

//    @Autowired
//   private OrgUserService orgUserService;

//   public void index() {
//       System.out.println("jjjj");
//   }

    /**
     * 获取当前登录用户
     * @param map
     * @return
     */
//    public CurUser curUser(){
//        Subject cur_user = SecurityUtils.getSubject();
//        Object userinfo = cur_user.getPrincipal();
//        CurUser curUser = new CurUser();
//        BeanUtils.copyProperties(userinfo,curUser);
//        return curUser;
//    }

//    @GetMapping({"/","/home/index"})
//    public String index(ModelMap map) {
//        map.put("cuser",curUser());
//        return "home/index";
//    }
    //初始登录
    @GetMapping({"/login","/home/login"})
    public String login(LoginForm loginForm , ModelMap map) {
        return "home/login";
    }
    //提交登录
//    @PostMapping({"/login","/home/login"})
//    public String login(@Valid LoginForm loginForm , BindingResult bindingResult, ModelMap map) {
//        if (bindingResult.hasErrors()) {
////            List<ObjectError> list = bindingResult.getAllErrors();
////            System.out.println(list);
////            for (ObjectError error :list) {
////                System.out.println(error.getDefaultMessage());
////            }
//            return "home/login";
//        } else {
//            Subject subject = SecurityUtils.getSubject();
//            UsernamePasswordToken token = new UsernamePasswordToken(loginForm.getAccount(), loginForm.getPasswd());
//            try {
//                subject.login(token);
//            } catch (AuthenticationException e) {
//                token.clear();
//                map.addAttribute("msgLogin","用户名或密码错误！请重试。");
//                return "home/login";
//            }
//            return "redirect:/home/index";
//        }
//    }

    /**
     * 修改当前登录用户密码
     */
//    @GetMapping("/home/pwdUpdate}")
//    public String pwdUpdate(@Valid PwdUpdateForm pwdUpdateForm, BindingResult bindingResult , ModelMap map){
//        OrgUser orgUser = orgUserService.getById(curUser().getCur_user_id());
//
//        return "home/pwdUpdate";
//    }

}
